package main

import (
	"flag"
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
)

func Routes() *gin.Engine {
	r := gin.New()
	r.GET("tar", func(c *gin.Context) {
		if err := HandWsTar(c); err != nil {
			c.AbortWithStatusJSON(http.StatusBadRequest, err)
			return
		}
	})
	r.GET("conn", func(c *gin.Context) {
		if err := HandWsOne(c); err != nil {
			c.AbortWithStatusJSON(http.StatusBadRequest, err)
			return
		}
	})
	return r
}

var port = flag.Int("p", 8888, "服务器端口")

func main() {
	flag.Parse()
	fmt.Println(fmt.Sprintf(":%v", port))
	r := Routes()
	if err := r.Run(fmt.Sprintf(":%v", *port)); err != nil {
		fmt.Println(err)
		return
	}
}
